var a = require("../../utils/api.js"), e = require("../../utils/disapi.js"), t = getApp(), o = Date.parse(new Date()) / 1e3;

Page({
    data: {
      user: {},
        grounhead: 1,
        show: !1,
        code: "",
        img: "",
        severPhone: "",
        version_num: "",
        commission: 2,
        carnum: "",
        footer: [],
        dis: 1,
        copyright_style: !1,
        copyright_text: !1,
        copyright_icon: !1,
        copyright_open: !1,
        showLoding: !0,
        showNum: 4,
        version_number_open: 1,
        teaminfo:{}
    },
    onLoad: function(e) {
        var o = this, n = e = e;
        wx.getSetting({
            success: function (e) {
                void 0 !== e.authSetting["scope.userInfo"] ? wx.getUserInfo({
                    success: function (e) {
                        var l = {
                            avatarUrl: e.userInfo.avatarUrl,
                            nickName: e.userInfo.nickName,
                            openid: wx.getStorageSync("openid"),
                            sessionkey: wx.getStorageSync("sessionkey")
                        };
                        console.log(l), a.inserUserdata(a).then(function (t) {
                            console.log(t);
                        });
                    },
                    fail: function () {
                    }
                }) : o.setData({
                    authorize: !0
                });
            }
        });
        a.getTeamOpenid({
            openid: t.globalData.openid
        }).then(function(t) {
            console.log(t,'========================') 
            t.data.head_info.m_last_location = t.data.head_info.m_last_location.replace(/,/g,'')
            o.setData({
                teaminfo:t.data.head_info
            })
        });
        if (o.setData({
            showLoding: !1,
            op: n
        }), 1 == t.globalData.is_first_enter) {
            // o.setData({
            //   ['user.m_nickname']: "点击登录",
            //   ['user.m_id']: ""
            // });
            console.log(o.data.user);
            // var s = o.route;
            // s = encodeURIComponent(s), console.log(s), wx.reLaunch({
            //     url: "/pages/authorization/authorization?url=" + s
            // });
      } 
        a.GetCopyrightSet({
            openid: t.globalData.openid
        }).then(function(a) {
            1 == a.errno && ("no" != a.data.copyright_style && o.setData({
                copyright_style: a.data.copyright_style.value
            }), "no" != a.data.copyright_text && o.setData({
                copyright_text: a.data.copyright_text.value
            }), "no" != a.data.copyright_icon && o.setData({
                copyright_icon: a.data.copyright_icon.value
            }), "no" != a.data.copyright_open && o.setData({
                copyright_open: a.data.copyright_open.value
            }), o.setData({
                version_number_open: a.data.version_number_open,
                diyPerson: a.data.diy_page.data[0],
                diyPage: a.data.diy_page.data
            }));
        }), a.getSeverPhone({}).then(function(a) {
            o.setData({
                severPhone: a.data.value
            });
        }), a.getTeamOpenid({
            openid: t.globalData.openid
        }).then(function(a) {
            console.log(a.data.head), o.setData({
                headInfo: a.data.head,
                head_info: a.data.head_info
            });
        }), a.plsugins({
            openid: t.globalData.openid,
            op: "sign"
        }).then(function(a) {
            console.log(a), 0 == a.code ? o.setData({
                plsugins: a.data.data,
                openplsugins: 1
            }) : o.setData({
                plsugins: "",
                openplsugins: 0
            });
        });
    },
    onPullDownRefresh: function() {
        var a = this;
        a.setData({
            showLoding: !1
        }), a.onShow(a.data.op);
    },
    code: function() {
        this.setData({
            show: !0
        });
    },
    codeClose: function() {
        this.setData({
            show: !1
        });
    },
    tel: function(a) {
        var e = a.currentTarget.dataset.phone;
        wx.makePhoneCall({
            phoneNumber: e
        });
    },
    getOrder: function(a) {
        var e = a.currentTarget.dataset.id;
        wx.navigateTo({
            url: "../order/orderList?id=" + e
        });
    },
    taps: function(a) {
        console.log(a);
    },
    onShow: function(n) {
        var s = this, i = n || "";
        s.setData({
            showLoding: !1,
            op: i
        });
        var r = 4;
        wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        });
        var d = a.getfooter();
        s.setData({
            footer: d
        });
        wx.getStorageSync("cartnum");
        s.setData({
            version_num: t.globalData.version_num,
            carnum: wx.getStorageSync("cartnum")
        }), n && n.type && "" != n.type && null != n.type && void 0 != n.type && wx.redirectTo({
            url: "../order/orderList?id=" + n.type
        });
        wx.getStorageSync("user");
        a.getMember({
            openid: t.globalData.openid
        }).then(function(n) {
          if (console.log(n), 1 != parseInt(n.data.is_show_card) && (r -= 1), wx.stopPullDownRefresh(),
            s.setData({
              user: n.data,
              img: n.data.qr_code,
              showLoding: !0
            }), 1 == n.data.distribution) {
            console.log(s.data.user);
                i = 1;
                e.get_dis_user_info({
                    openid: t.globalData.openid,
                    scene: "1"
                }).then(function(a) {
                    console.log(a), s.setData({
                        dis: a.errno,
                        stauts: a.errno
                  }), console.log(s.data.stauts);if (s.data.user.m_nickname == null) {
                    s.setData({
                      ['user.m_nickname']: "点击登录账户",
                    });
                  }; 
                 
                });
          }  else var i = 2;
            if (1 == n.data.fraction) d = 1; else {
                var d = 2;
                r -= 1;
            }
            if (0 != n.data.supplier) l = 1; else var l = 2;
            s.setData({
                commission: d,
                distribution: i,
                supplier: l,
                showNum: r
            }), "" != n.data.m_get_good_code && s.setData({
                code: n.data.m_get_good_code
            }), 2 == n.data.m_is_head ? s.setData({
                grounhead: 2
            }) : s.setData({
                grounhead: 1
            }), ("" == s.data.img || void 0 == s.data.img || parseInt(s.data.user.m_time) + parseInt(86400) < o) && a.getQRCode({
                openid: t.globalData.openid
            }).then(function(a) {
                console.log(a), 0 == a.errno ? s.setData({
                    img: a.data.data,
                    code: a.data.num
                }) : wx.showToast({
                    title: a.message,
                    icon: "none",
                    duration: 2e3
                });
            });
        }), console.log(s.data.showNum);
    },
    integral: function() {
        wx.navigateTo({
            url: "/pages/integralMall/index/index"
        });
    },
    goRefund: function(a) {
        wx.navigateTo({
            url: "../refund/refundList"
        });
    },
  goauthorization: function () {
    var o = this, n = e = e;
    if (o.setData({
      showLoding: !1,
      op: n
    }), 1 == t.globalData.is_first_enter) {
      var s = o.route;
      s = encodeURIComponent(s), console.log(s), wx.reLaunch({
        url: "/pages/authorization/authorization?url=" + s
      });
    } else {
      o.setData({
        showLoding: !0
      })
    }
  },
    sites: function(a) {
        var e = this;
        console.log(a);
        var t = a.currentTarget.dataset.data_index, o = e.data.footer, n = [ "/pages/template/index", "/pages/template/classify", "/pages/template/cart", "/pages/personal/personal" ];
        "url" == o.params.data[t].type ? n.includes(o.params.data[t].url) ? wx.reLaunch({
            url: o.params.data[t].url,
            success: function() {
                e.setData({
                    showLoding: !0
                });
            }
        }) : wx.navigateTo({
            url: o.params.data[t].url,
            success: function() {
                e.setData({
                    showLoding: !0
                });
            }
        }) : "tel" == o.params.data[t].type ? wx.makePhoneCall({
            phoneNumber: o.params.data[t].url
        }) : "out_link" == o.params.data[t].type ? wx.navigateTo({
            url: "/pages/template/out_h5?url=" + o.params.data[t].url
        }) : "app" == o.params.data[t].type && wx.navigateToMiniProgram({
            appId: o.params.data[t].url_name,
            path: o.params.data[t].url,
            envVersion: "develop",
            success: function(a) {}
        });
    },
    tofenxiao: function() {
        var a = this.data.stauts;
        console.log(a), 0 != a && 5 != a ? 2 != a ? 3 != a ? 4 != a || wx.navigateTo({
            url: "/pages/commission/register/index?stauts=4"
        }) : wx.navigateTo({
            url: "/pages/commission/index"
        }) : wx.navigateTo({
            url: "/pages/commission/register/index?stauts=2"
        }) : wx.navigateTo({
            url: "/pages/commission/index"
        });
    },
    stopscroll: function() {},
    rotate: function(e) {
        var t = this;
        if (console.log(e), t.setData({
            rotate: !0,
            showLoding: !1
        }), setTimeout(function() {
            t.setData({
                rotate: !1
            });
        }, 1e3), e.detail && e.detail.userInfo && e.detail.userInfo.avatarUrl) {
            var o = {
                avatarUrl: e.detail.userInfo.avatarUrl,
                nickName: e.detail.userInfo.nickName,
                openid: wx.getStorageSync("openid"),
                sessionkey: wx.getStorageSync("sessionkey")
            };
            console.log(o), a.inserUserdata(o).then(function(a) {
                console.log(a), 0 == a.errno ? t.onShow() : (t.onShow(), t.setData({
                    showLoding: !0
                }));
            });
        } else t.onShow(), t.setData({
            showLoding: !0
        });
    },
    govip: function() {
        wx.navigateTo({
            url: "/pages/member/recharge",
            success: function(a) {},
            fail: function(a) {},
            complete: function(a) {}
        });
    },
    site: function(a) {
        var e = this, t = e.data.diyPage, o = a.currentTarget.dataset.index, n = a.currentTarget.dataset.data_index, s = t[o].params.data[n].type, i = t[o].params.data[n].url;
        "url" == s ? wx.navigateTo({
            url: i
        }) : "tel" == s ? wx.makePhoneCall({
            phoneNumber: i
        }) : "out_link" == s ? (e.setData({
            url: i
        }), wx.navigateTo({
            url: "/pages/template/out_h5"
        })) : "app" == s && wx.navigateToMiniProgram({
            appId: t[o].params.data[n].url_name,
            path: i,
            envVersion: "develop",
            success: function(a) {}
        });
  },
});